﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Server;
using UCL.Powersource;

namespace UCL.Powersource.Mock
{
    [DataContract]
    public class DummyTimeframe : ITimeFrameIteration
    {
        public DummyTimeframe(string path, DateTime? date)
        {
            IterationPath = path;
            StartDate = date;
        }

        public string SourceBranchPath
        {
            get { return IterationPath; }
        }

        public void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public event PropertyChangedEventHandler PropertyChanged=null;

        public string Label
        {
            get 
            {
                return IterationPath.Replace("\\", "_"); ; 
            }
        }

        public string NodePath
        {
            get { return IterationPath; }
        }

        public string IterationPath
        {
            get;
            private set;
        }

        public DateTime? StartDate
        {
            get;
            private set;
        }

        public DateTime? FinishDate
        {
            get { if (StartDate != null) return ((DateTime)StartDate).AddDays(6); else return null; }
        }

        public string GetIterationPathForProject(ITfsTeamProjectConfiguration itpc)
        {
            return itpc.UniqueName + "\\" + IterationPath;
        }

        public void Merge(NodeInfo node)
        {
            return;
        }

        public TimeFrameTypes TimeFrameType
        {
            get 
            {
                if (IterationPath == null) return TimeFrameTypes.Unknown;
                else
                {
                    if (String.IsNullOrWhiteSpace(IterationPath)) return TimeFrameTypes.Project;
                    else
                    {
                        var containsSprint = IterationPath.ToLower().Contains("\\sprint");
                        var containsRelease = IterationPath.ToLower().Contains("\\release");
                        if (containsRelease && containsSprint) return TimeFrameTypes.Sprint;
                        if (containsRelease && !containsSprint) return TimeFrameTypes.Release;
                        return TimeFrameTypes.Unknown;
                    }
                }
            }
        }
    }
}
